package vn.orderonline.core.dao.temporaryorder;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import vn.orderonline.core.dao.common.GenericDaoImpl;
import vn.orderonline.core.dao.entity.TemporaryDrinkBasket;
import vn.orderonline.core.dao.entity.TemporaryDrinkBasketId;

@Repository
public class TemporaryDrinkBasketDaoImpl extends
		GenericDaoImpl<TemporaryDrinkBasket, TemporaryDrinkBasketId> implements
		TemporaryDrinkBasketDao {

	@Override
	public boolean checkExistDrink(Integer restaurantId, Integer drinkId) {
		if (restaurantId != null && drinkId != null) {
			Criteria criteria = getSession().createCriteria(TemporaryDrinkBasket.class);
			criteria.add(Restrictions.eq("id.restaurantId", restaurantId));
			criteria.add(Restrictions.eq("id.drinkId", drinkId));
			return (criteria.uniqueResult() != null) ? true : false;
		}
		return false;
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<TemporaryDrinkBasket> getListDrinkByRestaurantId(
			Integer restaurantId) {
		Criteria criteria = getSession().createCriteria(TemporaryDrinkBasket.class);
		criteria.add(Restrictions.eq("id.restaurantId", restaurantId));
		return criteria.list();
	}

}
